#ifndef TOOLBAR_H
#define TOOLBAR_H

#include <stddef.h>
//#include <raygui.h>

typedef struct ToolbarState
{
	int width, height;
	// Panels
	Vector2 anchorFile;
	Vector2 anchorEdit;
	Vector2 anchorTool;
	Vector2 anchorInfo;
	// Buttons
	int btnSize;
	Vector3 btnMargin;
	// File options
	bool btnNewPressed;
	bool btnOpenPressed;
	// Edit options
	bool btnFilePressed;
	bool btnFolderPressed;
	bool btnDeletePressed;
	bool btnExportPressed;
	// Tool options
	bool btnSavePressed;
	// Info options
	bool btnHelpPressed;
	bool btnInfoPressed;
} ToolbarState;

#ifdef __cplusplus
extern "C"
{
#endif // __cplusplus

ToolbarState initToolbar(Rectangle *rec)
{
	ToolbarState state = { 0 };

	state.width = rec->width;
	state.height = rec->height;
	// Panels
	state.anchorFile = (Vector2) { rec->x, rec->y };
	state.anchorEdit = (Vector2) { state.anchorFile.x + 76, 0 };
	state.anchorTool = (Vector2) { state.anchorEdit.x + 132, 0 };
	state.anchorInfo = (Vector2) { 0, 0 }; // Anchor right, depends on screen width

	// Buttons
	state.btnSize = 24;
	// left = 12, top = (height - btnSize) / 2 = 6, right = 4
	state.btnMargin = (Vector3) { 12, 6, 4 };
	// Press state
	state.btnNewPressed = false;
	state.btnOpenPressed = false;
	state.btnFilePressed = false;
	state.btnFolderPressed = false;
	state.btnDeletePressed = false;
	state.btnExportPressed = false;
	state.btnSavePressed = false;
	state.btnHelpPressed = false;
	state.btnInfoPressed = false;

	return state;
}

void drawToolbar(ToolbarState *state)
{
	state->anchorInfo.x = state->width - 76; // Update right-anchor panel

	// Enable tooltips by default
	GuiEnableTooltip();

	GuiPanel((Rectangle) { state->anchorFile.x, state->anchorFile.y, state->anchorEdit.x - state->anchorFile.x + 1, state->height }, NULL);
	GuiPanel((Rectangle) { state->anchorEdit.x, state->anchorEdit.y, state->anchorTool.x - state->anchorEdit.x + 1, state->height }, NULL);
	GuiPanel((Rectangle) { state->anchorTool.x, state->anchorTool.y, state->anchorInfo.x - state->anchorTool.x + 1, state->height }, NULL);
	GuiPanel((Rectangle) { state->anchorInfo.x, state->anchorInfo.y, 76, state->height }, NULL);

	// File Panel - |12|24|4|24|12|
	GuiSetTooltip("Create new package (LCTRL+N)");
	state->btnNewPressed = GuiButton((Rectangle) { state->anchorFile.x + state->btnMargin.x, state->anchorFile.y + state->btnMargin.y, state->btnSize, state->btnSize }, "#203#");
	GuiSetTooltip("Open package file (LCTRL+O)");
	state->btnOpenPressed = GuiButton((Rectangle) { state->anchorFile.x + state->btnMargin.x + (state->btnSize + state->btnMargin.z), state->anchorFile.y + state->btnMargin.y, state->btnSize, state->btnSize }, "#5#");

	// Edit Panel - |12|24|4|24|4|24|4|24|12|
	GuiSetTooltip("Add file (LCTRL+F)");
	state->btnFilePressed = GuiButton((Rectangle) { state->anchorEdit.x + state->btnMargin.x, state->anchorEdit.y + state->btnMargin.y, state->btnSize, state->btnSize }, "#8#");
	GuiSetTooltip("Add folder (LCTRL+D)");
	state->btnFolderPressed = GuiButton((Rectangle) { state->anchorEdit.x + state->btnMargin.x + (state->btnSize + state->btnMargin.z), state->anchorEdit.y + state->btnMargin.y, state->btnSize, state->btnSize }, "#204#");
	GuiSetTooltip("Remove file (DELETE)");
	state->btnDeletePressed = GuiButton((Rectangle) { state->anchorEdit.x + state->btnMargin.x + (state->btnSize + state->btnMargin.z) * 2, state->anchorEdit.y + state->btnMargin.y, state->btnSize, state->btnSize }, "#9#");
	GuiSetTooltip("Export file (LCTRL+E)");
	state->btnExportPressed = GuiButton((Rectangle) { state->anchorEdit.x + state->btnMargin.x + (state->btnSize + state->btnMargin.z) * 3, state->anchorEdit.y + state->btnMargin.y, state->btnSize, state->btnSize }, "#7#");

	// Tool Panel - |12|24|...|
	GuiSetTooltip("Save package file (LCTRL+S)");
	state->btnSavePressed = GuiButton((Rectangle) { state->anchorTool.x + state->btnMargin.x, state->anchorTool.y + state->btnMargin.y, state->btnSize, state->btnSize }, "#2#");

	// Info Panel - |12|24|4|24|12|
	GuiSetTooltip("Help window (F1)");
	state->btnHelpPressed = GuiButton((Rectangle) { state->anchorInfo.x + state->btnMargin.x, state->anchorInfo.y + state->btnMargin.y, state->btnSize, state->btnSize }, "#193#");
	GuiSetTooltip("Info window (F2)");
	state->btnInfoPressed = GuiButton((Rectangle) { state->anchorInfo.x + state->btnMargin.x + (state->btnSize + state->btnMargin.z), state->anchorInfo.y + state->btnMargin.y, state->btnSize, state->btnSize }, "#191#");

	GuiDisableTooltip();
}

#ifdef __cplusplus
}
#endif // __cplusplus

#endif // TOOLBAR_H